/**
 * 广告数据
 */
let that = null
const getAdData = (_this) => {
  that = _this
  return new Promise((resolve, reject) => {
    getManuAdvCommon(
      '通用自定义弹窗',
      'AD_POP_COMMON',
      1,
      1,
      that.adRequestTimes,
      that.indexBoost,
      that.isBidding,
      that.preDeleteStatus,
      that.index,
      that.adTypes
    ).then((res) => {
      resolve(res.data)
    })
  })
}
/**
 * 通用获取原生广告函数
 * @param {String} scenario 广告来源名称
 * @param {String} sceneCode 广告场景ID
 * @param {String} adType 广告类型 0默认 1原生 2 2.0 3百度
 * @param {String} adTimes 广告请求轮数0 1 2
 * @param {String} popName 弹窗名称
 * @param {String} popGroupName 弹窗组名称
 * @param {String} requestNum 广告请求位置 1 2 3
 */
const getManuAdvCommon = (
  scenario,
  sceneCode = '',
  adType = 0,
  adTimes = 0,
  requestNum = 1,
  indexBoost = 0,
  isBidding,
  preDeleteStatus,
  index,
  adTypes
) => {
  let popGroupName = '广告池'
  let popName = '广告池'
  let scene = that.isScene ? `补量请求-${isBidding ? 'bidding' : '底价'}` : `自动请求-${isBidding ? 'bidding' : '底价'}`
  return new Promise((resolve, reject) => {
    AD_SDK_UTILS.getAd({
      scenario,
      sceneCode,
      adType,
      adTimes,
      popName,
      popGroupName,
      requestNum,
      indexBoost,
      scene,
      isBidding,
      preDeleteStatus,
      index,
      adTypes,
      success: function (res) {
        resolve({
          type: 'success',
          data: res,
        })
      },
      fail: function (err) {
        resolve({
          type: 'failed',
          data: err,
        })
      },
    })
  })
}
/**
 * 广告图片展示
 * @description 目前的广告展示 是提前于弹窗展示的
 */
const adPicShowFunc = (_this) => {
  that = _this
  console.log("ad_show_report")
  AD_SDK.uploadAdInfo('show', that.nativeAdvObj)
}
//上报点击
const reportClick = (_this, element) => {
  that = _this
  if (element == '上一页' || element == '下一页') return
  if (that.nativeIsShowPop) {
    let param = {
      ad_network: that.nativeAdvObj.ad_network,
      page_type: that.curpopConfig.popGroupName,
      ad_position: that.curpopConfig.popName,
      ad_style: AD_SDK.ad_sdk_global.popShowNum + '',
      page_name: '有',
      ext_field_9: that.action2Name(that.actionCode),
      scene: that.nativeAdvObj.scene,
      ext_field_2: that.nativeAdvObj.layer >= 0 ? that.nativeAdvObj.layer + 1 + '' : '1',
      element: element,
      ad_id: that.nativeAdvObj.id || '',
      referer: '有广告弹窗',
      ad_type: that.nativeAdvObj.ad_type,
      ext_field_8: that.nativeAdvObj.advDetail ? that.nativeAdvObj.advDetail.appInfo ? that.nativeAdvObj.advDetail.appInfo.appName : that.nativeAdvObj.advDetail.appName || that.nativeAdvObj.title || that.nativeAdvObj.advDetail.title : '',
      ext_field_1: that.nativeAdvObj.isBidding && that.nativeAdvObj.advDetail ? that.nativeAdvObj.advDetail.ecpm + '' : '',
      ext_field_3: that.nativeAdvObj.adRegion || '',
      ext_field_6: that.nativeAdvObj.client || ''
    }
    POP_TOOLS.resetActionPopType()
    COMMON_REPORT_UTILS.custom_popup_click_report(
      param.page_type,
      param.ad_position,
      param.ad_network,
      param.element,
      param.ad_style,
      param.page_name,
      param.ext_field_9,
      param.ext_field_2,
      param.ad_id,
      param.scene,
      param.referer,
      param.ad_type,
      param.ext_field_8,
      param.ext_field_1,
      param.ext_field_3,
      param.ext_field_6,
    )
  } else {
    COMMON_REPORT_UTILS.page_click_report(element)
  }
}
const adUtil = {
  getAdData,
  adPicShowFunc,
  reportClick,
}
export default adUtil
